package com.sunshine.common.enums;

import lombok.Getter;

/**
 * 响应码枚举
 * @version 1.0
 * @Author 夏百友
 * @Date 2025/11/2 16:42
 */

@Getter
public enum ResultCodeEnum {

    Success(200, "成功"),
    Fail(500, "失败"),
    Unauthorized(401, "未授权"),
    Forbidden(403, "禁止访问"),
    NotFound(404, "未找到"),
    ServerError(500, "服务器错误"),
    BadRequest(400, "请求错误"),
    UnsupportedMediaType(415, "不支持的媒体类型"),
    MethodNotAllowed(405, "不允许的方法"),
    NotAcceptable(406, "不允许的格式"),
    RequestTimeout(408, "请求超时"),
    Conflict(409, "冲突"),
    Gone(410, "已删除"),
    UnprocessableEntity(422, "无法处理"),
    ParameterError(400, "参数错误");

    private int code;
    private String desc;
    
    ResultCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public static ResultCodeEnum getByCode(int code){
        for (ResultCodeEnum value : ResultCodeEnum.values()) {
            if (value.code == code) {
                return value;
            }
        }
        return null;
    }


}